<?php
/*
该文件为核心文件。主要有负责所有文件整合执行的函数。
注：includeViewFile()函数暂时为了测试写的函数。执行这个页面，只要是放在view文件夹的php文件都会被执行。
*/

function checkModelFileName(){
	$arrayfile=getfileName(dirname(dirname(dirname(__FILE__))).'/model');
	foreach($arrayfile as $num=>$filename){
		$fileContent=stringToExec(dirname(__FILE__).'/../../model/'.$filename);
		$arrayname=explode("{",$fileContent);
		$arrayname1=explode(" ",$arrayname[0]);
		$className=trim($arrayname1[1]);
		$filename=preg_replace("/\..*/","",$filename);   
		if(trim($filename)!=trim($className))
		{
			echo 'Model文件名与所属类名不一致';
			die();
			return false;
		}
	}
	return true;
	
}

function stringToExec($file){
	$fileContent=file_get_contents($file);
	$fileContent=str_replace(array("<?php","<?","?>"),"",$fileContent);
	$fileContent=preg_replace("/\/\*.*\*\//Us","",$fileContent);   
	$fileContent=preg_replace("/\/\/[^\r\n\'\"]*[\r\n]/","",$fileContent);  
	$fileContent=preg_replace("/\/\*.*/s","",$fileContent); 
	return $fileContent;
}

function getfileName($dir){
	$array=array();
	$handler = opendir($dir);
	while( ($filename = readdir($handler)) !== false ) 
		if($filename != '.' && $filename != '..')
			array_push($array,$filename);
	closedir($handler);
	return $array;
}


function includeViewFile(){
	$arrayfile=getfileName(dirname(dirname(dirname(__FILE__))).'/view');
	foreach($arrayfile as $num=>$file){
		$fileContent=file_get_contents(dirname(dirname(dirname(__FILE__))).'/view/'.$file);
		$fileContent=str_replace(array("<?php","<?","?>"),"",$fileContent);
		echo"View Page  $file :<br />";
		eval($fileContent);
	}
}




?>